/*	HTML5AS3MultiUp v0.1 <http://code.google.com/p/html5-as3-multiupload/> 
	is released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

package flasheep.proj.multiup.as3.ui 
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	/**
	 * ...
	 * @author Luan(tonylua@sina.com)
	 */
	public class AssetBtn extends Sprite 
	{
		private var _up:DisplayObject;
		private var _over:DisplayObject;
		
		public function AssetBtn(btnimg:String, btnoverimg:String) 
		{
			this.buttonMode = true;
			
			this.addChild(_drawFallback('loading...'));
			
			this.addChild(_over = _getAsset(btnoverimg));
			this.addChild(_up = _getAsset(btnimg));
			
			this.addEventListener(MouseEvent.MOUSE_OVER, function(evt:Event):void {
				_over.visible = true;
				_up.visible = false;
			});
			this.addEventListener(MouseEvent.MOUSE_OUT, function(evt:Event):void {
				_over.visible = false;
				_up.visible = true;
			});
		}
		
		private function _getAsset(path:String):DisplayObject
		{
			var ldr:Loader = new Loader;
			//ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, function(evt:Event):void {
				//
			//} );
			ldr.load(new URLRequest(path));
			return ldr;
		}
		
		private function _drawFallback(txt:String):DisplayObject
		{
			var tf:TextField = new TextField;
			tf.text = txt;
			return tf;
		}
	}
}